/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package autodiarydataprocess;

import java.io.File;
import org.encog.ml.data.MLData;
import org.encog.ml.data.basic.BasicMLData;
import org.encog.neural.data.NeuralData;
import org.encog.neural.data.basic.BasicNeuralData;
import org.encog.neural.networks.BasicNetwork;
import org.encog.neural.som.SOM;
import org.encog.persist.EncogDirectoryPersistence;
import org.neuroph.core.NeuralNetwork;

/**
 *
 * @author kkkkkkkkkkkk
 */
public class AutoDiaryDataProcess {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        testEncog();
        //testEncogCompatitive();
        //testNeuroph();
        //prepareTrainData();
    }
    
    public static void prepareTrainData(){
        TrainingData prepare = new TrainingData();
        // NN output:
        // 00: walking
        // 01: running
        // 10: Driving
        // 11: Still
        
        
        //prepare.minMax01Range("F:/E/study/autoDiaryData/Training/softwalk.txt", "F:/E/study/autoDiaryData/Training/softwalkMinMax01.txt", "F:/E/study/autoDiaryData/Training/softwalkWindow.txt", "0,0");
                
        /*        
        prepare.minMinus01Range("F:/E/study/projects/AutoDiary/data/data8Walk.txt", "F:/E/study/projects/AutoDiary/data/data8WalkMinMinus01.txt", "F:/E/study/projects/AutoDiary/data/data8WalkWindow.txt", "0,0");
        prepare.minMinus01Range("F:/E/study/projects/AutoDiary/data/data1Walk.txt", "F:/E/study/projects/AutoDiary/data/data1WalkMinMinus01.txt", "F:/E/study/projects/AutoDiary/data/data1WalkWindow.txt", "0,0");
        prepare.minMinus01Range("F:/E/study/projects/AutoDiary/data/data2Run.txt", "F:/E/study/projects/AutoDiary/data/data2RunMinMinus01.txt", "F:/E/study/projects/AutoDiary/data/data2RunWindow.txt", "0,1");
        prepare.minMinus01Range("F:/E/study/projects/AutoDiary/data/data6Driving.txt", "F:/E/study/projects/AutoDiary/data/data6DrivingMinMinus01.txt", "F:/E/study/projects/AutoDiary/data/data6DrivingWindow.txt", "1,0");
        prepare.minMinus01Range("F:/E/study/projects/AutoDiary/data/data7Still.txt", "F:/E/study/projects/AutoDiary/data/data7StillMinMinus01.txt", "F:/E/study/projects/AutoDiary/data/data7StillWindow.txt", "1,1");
        */
        
        //prepare.prepareData("F:/E/study/projects/AutoDiary/data/data1Walk.txt", "F:/E/study/projects/AutoDiary/data/data1WalkMinMaxAvr.txt", "F:/E/study/projects/AutoDiary/data/data1WalkWindow.txt", "1,0,0,0");
        //prepare.prepareData("F:/E/study/projects/AutoDiary/data/data2Run.txt", "F:/E/study/projects/AutoDiary/data/data2RunMinMaxAvr.txt", "F:/E/study/projects/AutoDiary/data/data2RunWindow.txt", "0,1,0,0");
        //prepare.prepareData("F:/E/study/projects/AutoDiary/data/data6Driving.txt", "F:/E/study/projects/AutoDiary/data/data6DrivingMinMaxAvr.txt", "F:/E/study/projects/AutoDiary/data/data6DrivingWindow.txt", "0,0,1,0");
        //prepare.prepareData("F:/E/study/projects/AutoDiary/data/data7Still.txt", "F:/E/study/projects/AutoDiary/data/data7StillMinMaxAvr.txt", "F:/E/study/projects/AutoDiary/data/data7StillWindow.txt", "0,0,0,1");

        //prepare.prepareBinary("F:/E/study/projects/AutoDiary/data/data1Walk.txt", "F:/E/study/projects/AutoDiary/data/data1WalkMaxMinusMinBinary.txt", "F:/E/study/projects/AutoDiary/data/data1WalkWindow.txt", "1,0,0,0");
        //prepare.prepareBinary("F:/E/study/projects/AutoDiary/data/data2Run.txt", "F:/E/study/projects/AutoDiary/data/data2RunMaxMinusMinBinary.txt", "F:/E/study/projects/AutoDiary/data/data2RunWindow.txt", "0,1,0,0");
        //prepare.prepareBinary("F:/E/study/projects/AutoDiary/data/data6Driving.txt", "F:/E/study/projects/AutoDiary/data/data6DrivingMaxMinusMinBinary.txt", "F:/E/study/projects/AutoDiary/data/data6DrivingWindow.txt", "0,0,1,0");
        //prepare.prepareBinary("F:/E/study/projects/AutoDiary/data/data7Still.txt", "F:/E/study/projects/AutoDiary/data/data7StillMaxMinusMinBinary.txt", "F:/E/study/projects/AutoDiary/data/data7StillWindow.txt", "0,0,0,1");
    }
    
    /*
     * use Encog to load and run neural network from:
     * F:\E\study\projects\AutoDiaryNN\Encog\Test1\WRDS.eg
     */
    public static void testEncog()
    {
        System.out.print("Loading network");
        
        // load the saved network
        //BasicNetwork network = (BasicNetwork)EncogDirectoryPersistence.loadObject(new File("F:/E/study/projects/AutoDiaryNN/Encog/Test1/WRDS.eg"));
        BasicNetwork network = (BasicNetwork)EncogDirectoryPersistence.loadObject(new File("F:/E/study/projects/AutoDiaryNN/Encog/version2/WRDS120625V4-5.eg"));
        
        // set network input and calculate
        //double[] nnInput = {0.1765, 0.732};
        double[] nnInput = {0.452, 0.175}; 
        double[] nnOutput = new double[2];
        network.compute(nnInput, nnOutput);
        
       
        // display on screen
        System.out.print("Output: ");
        for (double d: nnOutput){
            System.out.print(d + ",");
        }
    }
    
    public static void testEncogCompatitive()
    {
        System.out.println("Loading compatitive network");
        
        // load the saved network
        //BasicNetwork network = (BasicNetwork)EncogDirectoryPersistence.loadObject(new File("F:/E/study/projects/AutoDiaryNN/Encog/Test1/WRDS.eg"));
        SOM network = (SOM)EncogDirectoryPersistence.loadObject(new File("F:/E/study/projects/AutoDiaryNN/Encog/version2/WRDS120619V3.eg"));
        
        // set network input and calculate
        double[] arrInput = {0.154, 0.7905};
        BasicNeuralData nnInput = new BasicNeuralData(arrInput);
        MLData nnOutput = network.compute(nnInput);
        //System.out.println( "Winer: " + nnOutput.network.compute(nnInput) );
        
       
        // display on screen
        System.out.print("Output: ");
        for ( double d: nnOutput.getData() ){
            System.out.print(d + ",");
        }
    }

    
    /*
     * load and run neural network from:
     * F:\E\study\projects\AutoDiaryNN\pimaryActivities\Neural Networks\multiLayerPerceptron.nnet
     */
    public static void testNeuroph()
    {
        // load the saved network
        NeuralNetwork myNN = NeuralNetwork.load("F:/E/study/projects/AutoDiaryNN/pimaryActivities/Neural Networks/multiLayerPerceptron.nnet");
        
        // set network input
        myNN.setInput(0.1765, 0.732);
        
        // calculate network
        myNN.calculate();
        
        // get network output
        double[] nnOut = myNN.getOutput();
        
        // display on screen
        System.out.print("Output: ");
        for (double d: nnOut){
            System.out.print(d + ",");
        }
    }
}
